<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>
<head>
<title> <spring:message code="admin.viewbonuspayment.title" /></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>"></script>

</head>

<body><%@include file="../top_menu.jsp"%>
<table width=100%>
	<tr>
		<td><c:import url="/WEB-INF/jsp/menu/admin_bonus_menu.jsp" /><br />
		</td>
	</tr>
	<tr>
		<td><%@include file="/WEB-INF/jsp/include/messages.jsp"%>
		<br />
		</td>
	</tr>
</table>

<table width=70% class="formTable">

	<tr class="formHeader">
		<td colspan="5"><spring:message code="admin.viewbonuspayment.label.bonusreport" /></td>
	</tr>

	<tr>
		<td colspan="2">
		<table>
			<c:if test="${bonus != null}">
				<tr>
					<td colspan="2">
					<table>
						<tr>
							<td colspan="2">
							<h3><spring:message code="admin.viewbonuspayment.label.yourbonusplanid" /> <a
								href="javascript:history.back();">${bonus.id}
							(${bonus.name})</a></h3>
							</td>
						</tr>
						<tr>
							<td colspan="2"><spring:message code="admin.viewbonuspayment.label.supposetoget" />:</td>
						</tr>
						<c:if test="${bonus.methodId == 1}">
							<c:set var="amountSuffix" value="$"></c:set>
							<c:if test="${bonus.typeId == 2}">
								<c:set var="amountSuffix" value="%"></c:set>
							</c:if>

							<c:forEach items="${bonus.details.desiredAmounts}"
								var="desiredAmount" varStatus="i">
								<tr>
									<td>${bonus.columnName} ${bonus.operator} ${desiredAmount}
									<spring:message code="admin.viewbonuspayment.label.youwillget" /> <c:if test="${bonus.typeId == 1}"> ${bonus.details.flatRates[i.index]} </c:if>
									<c:if test="${bonus.typeId == 2}"> ${bonus.details.percentRates[i.index]} </c:if>
									${amountSuffix}</td>
								</tr>
							</c:forEach>

							<tr>
								<td colspan="2"><br />
								<spring:message code="admin.viewbonuspayment.label.performedsofarbonus" />:</td>
							</tr>
							<tr>
								<td colspan="2">${bonus.columnName} =
								${bonusResult.actualAmount} <spring:message code="admin.viewbonuspayment.label.youearned" />
								$${bonusResult.calculatedAmount} (unpaid balance
								${bonusResult.unpaidBalance})</td>
							</tr>

							<c:forEach items="${bonus.bonusPayments}" var="p" varStatus="i">
								<tr>
									<td colspan="2"><a
										href="view_bonus_payment.htm?id=${p.id}"><spring:message code="admin.viewbonuspayment.label.payment" /> #${p.id}</a></td>
								</tr>
							</c:forEach>



						</c:if>


						<c:if test="${bonus.methodId == 2}">

							<tr>
								<td><spring:message code="admin.viewbonuspayment.lable.ifyoureferredmoreserviceproviders" arguments="${bonus.providerCount}" />.<br />
								<spring:message code="admin.viewbonuspayment.lable.eachserviceproviderrefers" arguments="${bonus.customerCount}" />.<br />
								<spring:message code="admin.viewbonuspayment.lable.customerhasatleasttransactions" arguments="${bonus.transactionCount}" /> <br />
								<spring:message code="admin.viewbonuspayment.lable.youwillgetbonus" arguments="${bonus.payPerUnit},${bonus.payUnit}" />.</td>
							</tr>


							<tr>
								<td colspan="2"><br />
								<spring:message code="admin.viewbonuspayment.label.performedsofarbonus" />:</td>
							</tr>
							<tr>
								<td colspan="2">
								<table border="1">
									<tr>
										<td><spring:message code="admin.viewbonuspayment.lable.serviceprovidername" /></td>
										<td><spring:message code="admin.viewbonuspayment.lable.serviceproviderid" /></td>
										<td><spring:message code="admin.viewbonuspayment.lable.numberofcustomers" /></td>
										<td><spring:message code="admin.viewbonuspayment.lable.totaltransactions" /></td>
										<td><spring:message code="admin.viewbonuspayment.lable.bonusearned" /></td>
										<td><spring:message code="admin.viewbonuspayment.lable.unpaidbalance" /></td>
									</tr>

									<c:set var="totalCustomers" value="0"></c:set>
									<c:set var="totalTransactions" value="0"></c:set>
									<c:set var="totalBonusEarned" value="0"></c:set>

									<c:forEach items="${bonusResult.details}" var="dtl"
										varStatus="i">
										<tr>
											<td>${dtl.serviceProviderName}</td>
											<td>${dtl.serviceProviderId}</td>
											<td>${dtl.customerCount}</td>
											<td>${dtl.transactionCount}</td>
											<td>${dtl.bonusEarned}</td>
											<td>N/A</td>

											<c:set var="totalCustomers"
												value="${totalCustomers+dtl.customerCount}"></c:set>
											<c:set var="totalTransactions"
												value="${totalTransactions+dtl.transactionCount}"></c:set>
											<c:set var="totalBonusEarned"
												value="${totalBonusEarned+dtl.bonusEarned}"></c:set>

										</tr>
									</c:forEach>

									<tr>
										<td colspan="2" align="center"><spring:message code="admin.viewbonuspayment.lable.totals" /></td>
										<td>${totalCustomers}</td>
										<td>${totalTransactions}</td>
										<td>${totalBonusEarned}</td>
										<td>${bonusResult.unpaidBalance}</td>
									</tr>
								</table>
								</td>
							</tr>
						</c:if>

						<tr>
							<td colspan="2"><spring:message code="admin.viewbonuspayment.lable.paymentdetails" /></td>
						</tr>
						<tr>
							<td colspan="2">
							<table border="1">
								<tr>
									<td><spring:message code="admin.viewbonuspayment.lable.paymentid" /></td>
									<td><spring:message code="admin.viewbonuspayment.lable.paymentdate" /></td>
									<td><spring:message code="admin.viewbonuspayment.lable.amount" /></td>
									<td><spring:message code="admin.viewbonuspayment.lable.unpaidalance" /></td>
								</tr>
								<tr>
									<td>${payment.id}</td>
									<td>${payment.payDate}</td>
									<td>${payment.amount}</td>
									<td>${bonusResult.unpaidBalance}</td>
								</tr>
							</table>
							</td>
						</tr>

					</table>
					</td>
				</tr>
			</c:if>
		</table>
		</td>
	</tr>


</table>
<%@include file="/WEB-INF/jsp/include/footer.jsp"%>
</body>
</html>